fork download
  1. #include<iostream>
  2. #include<vector>
  3. #include<set>
  4. using namespace std;
  5.  
  6. int add(int a, int b) {
  7. return a + b;
  8. }
  9.  
  10. float add(float a, float b) {
  11. return a + b;
  12. }
  13.  
  14. int add(vector<int> v) {
  15. int sum = 0;
  16. for (auto i : v)
  17. sum += i;
  18. return sum;
  19. }
  20.  
  21. int add(set<int> st) {
  22. int sum = 0;
  23. for (auto i : st)
  24. sum += i;
  25. return sum;
  26. }
  27.  
  28. bool search(int key, set<int> data_structure) {
  29. return data_structure.find(key) != data_structure.end();
  30. }
  31.  
  32. int main() {
  33. set<int> st;
  34. int n, a;
  35. cout << "Enter the number of elements: ";
  36. cin >> n;
  37. cout << "Enter the elements:\n";
  38. for (int i = 0; i < n; i++) {
  39. cin >> a;
  40. st.insert(a);
  41. }
  42.  
  43. cout << "Sum of elements in the set: " << add(st) << endl;
  44.  
  45. int keyToSearch;
  46. cout << "Enter the key to search: ";
  47. cin >> keyToSearch;
  48. if (search(keyToSearch, st))
  49. cout << "Key found!\n";
  50. else
  51. cout << "Key not found!\n";
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Enter the number of elements: Enter the elements:
Sum of elements in the set: 2072339360
Enter the key to search: Key not found!